import 'package:flame_audio/flame_audio.dart';

//音乐
class AudioHelper {
  AudioHelper._internal();

  static final AudioHelper _instance = AudioHelper._internal();

  factory AudioHelper() => _instance;

  // 初始化
  init() {
    FlameAudio.bgm.initialize();
  }

  // 销毁
  release() {
    FlameAudio.bgm.dispose();
  }

  // 循环播放
  playBgm(String name, double volume) {
    FlameAudio.bgm.play(name, volume: volume);
  }

  loadAll(List<String> names) async {
    await FlameAudio.audioCache.loadAll(names);
  }

  // 播放
  play(String name, double volume) {
    FlameAudio.play(name, volume: volume);
  }

  // 停止
  stop() {
    FlameAudio.bgm.stop();
  }

  // 循环播放
  Future<AudioPlayer> loop(String name, double volume) {
    return FlameAudio.loop(name, volume: volume);
  }
}
